package base.oop;

import java.util.List;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * @Author Fizz Pu
 * @Date 2021/4/5 下午3:20
 * @Version 1.0
 * 失之毫厘，缪之千里！
 */
public class Processor {
    public String getName(){
        return this.getClass().getName();
    }

    public Object process(Object object){
        return object;
    }
}

class UpperProcess extends Processor{
    @Override
    public String process(Object object){ // 返回协变类型
        String str = (String)object;
        return str.toUpperCase();
    }
}

class LowerProcess extends Processor{
    @Override
    public String process(Object object){
        return ((String)object).toLowerCase();
    }
}

class SplitProcess extends Processor{
    @Override
    public String process(Object ob){
        String[] arr = ((String)ob).split(" ");
        return Arrays.toString(arr);
    }
}

class Apply{
    public static void apply(Processor processor, Object ob){
        System.out.println(("Using Processor name : " + processor.getName()));
        System.out.println(processor.process(ob));
    }

    static String str = "jiu ff fs ffs  fjsij fsjn fsfji";

    public static void main(String[] args) throws IllegalAccessException, InstantiationException {
        Class<? extends Processor>[] classes = new Class[]{
                Processor.class, SplitProcess.class, LowerProcess.class, UpperProcess.class
        };
        List<Processor> processorList = new ArrayList<>();

        for(Class cl: classes){
            Processor instance =  (Processor) cl.newInstance();
            processorList.add(instance);
        }

        for(Processor processor: processorList){
            Apply.apply(processor, str);
        }
    }
}

// 算法固定抽象出来
